<template>
  <div id="center">
    <div class="top">
      <div
        class="bg-color-black item"
        :key="totalItem.title"
      >
        <p class="ml-3 colorBlue fw-b fs-xl" style="text-align: center; align-content: center; margin: 0 auto">{{ totalItem.title }}</p>
        <div>
          <dv-digital-flop
            class="dv-dig-flop ml-1 mt-2 pl-3"
            style="margin: 10px auto"
            :config="totalItem.number"
          />
        </div>
      </div>
    </div>
    <div class="up">
      <div
        class="bg-color-black item"
        v-for="item in bigTitleItem"
        :key="item.title"
      >
        <p class="ml-3 colorBlue fw-b fs-xl">{{ item.title }}</p>
        <div>
          <dv-digital-flop
            class="dv-dig-flop ml-1 mt-2 pl-3"
            :config="item.number"
          />
        </div>
      </div>
    </div>
    <div class="down">
      <div
        class="bg-color-black item"
        v-for="item in titleItem"
        :key="item.title"
      >
        <p class="ml-3 colorBlue fw-b fs-xl">{{ item.title }}</p>
        <div>
          <dv-digital-flop
            class="dv-dig-flop ml-1 mt-2 pl-3"
            :config="item.number"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CenterChart from '@/components/echart/center/centerChartRate'
import { overview } from "@/api/statics/dataview";

export default {
  props: {
    shop: {
      type: String,
      default: () => ''
    }
  },
  data() {
    return {
      totalItem: {
        title: '支付总金额',
        number: {
          number: [0],
          toFixed: 2,
          textAlign: 'left',
          content: '￥{nt}',
          style: {
            fontSize: 26
          }
        }
      },
      bigTitleItem: [
        {
          title: '订单成本',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '订单数量',
          number: {
            number: [0],
            toFixed: 0,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '订单利润',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        }
      ],
      titleItem: [
        {
          title: '昨日订单数',
          number: {
            number: [0],
            toFixed: 0,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '昨日成交数',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '昨日利润',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '昨日订单成本',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '本月订单数',
          number: {
            number: [0],
            toFixed: 0,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '本月成交额',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '本月利润',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        },
        {
          title: '本月订单成本',
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        }
      ],
      ranking: {
        data: [
          {
            name: '周口',
            value: 55
          },
          {
            name: '南阳',
            value: 120
          },
          {
            name: '西峡',
            value: 78
          },
          {
            name: '驻马店',
            value: 66
          },
          {
            name: '新乡',
            value: 80
          },
          {
            name: '新乡2',
            value: 80
          },
          {
            name: '新乡3',
            value: 80
          },
          {
            name: '新乡4',
            value: 80
          },
          {
            name: '新乡5',
            value: 80
          },
          {
            name: '新乡6',
            value: 80
          }
        ],
        carousel: 'single',
        unit: '人'
      },
      water: {
        data: [24, 45],
        shape: 'roundRect',
        formatter: '{value}%',
        waveNum: 3
      },
      // 通过率和达标率的组件复用数据
      rate: [
        {
          id: 'centerRate1',
          tips: 60,
          colorData: {
            textStyle: '#3fc0fb',
            series: {
              color: ['#00bcd44a', 'transparent'],
              dataColor: {
                normal: '#03a9f4',
                shadowColor: '#97e2f5'
              }
            }
          }
        },
        {
          id: 'centerRate2',
          tips: 40,
          colorData: {
            textStyle: '#67e0e3',
            series: {
              color: ['#faf3a378', 'transparent'],
              dataColor: {
                normal: '#ff9800',
                shadowColor: '#fcebad'
              }
            }
          }
        }
      ]
    }
  },
  components: {
    CenterChart
  },
  watch: {
    shop() {
      this.getOverview()
    }
  },
  mounted() {
    this.getOverview()
    this.changeTiming()
  },
  methods: {
    getOverview() {
      const params = {}
      if (this.shop && this.shop !== '') {
        params.shopName = this.shop
      }
      overview(params).then(res => {
        const data = res.data.data
        const totalItem = this.totalItem
        totalItem.number.number[0] = data.all.amount
        totalItem.number = { ...totalItem.number }

        this.bigTitleItem.forEach((item, index) => {
          if (item.title === '订单成本') {
            item.number.number[0] = data.all.cost
          }
          if (item.title === '订单数量') {
            item.number.number[0] =  data.all.count
          }
          if (item.title === '订单利润') {
            item.number.number[0] =  data.all.profit
          }
          item.number = { ...item.number }
        })

        this.titleItem.forEach((item, index) => {
          if (item.title === '昨日订单数') {
            item.number.number[0] = data.yesterday.count
          }
          if (item.title === '昨日成交数') {
            item.number.number[0] =  data.yesterday.amount
          }
          if (item.title === '昨日利润') {
            item.number.number[0] =  data.yesterday.profit
          }
          if (item.title === '昨日订单成本') {
            item.number.number[0] =  data.yesterday.cost
          }
          if (item.title === '本月订单数') {
            item.number.number[0] =  data.month.count
          }
          if (item.title === '本月成交数') {
            item.number.number[0] =  data.month.amount
          }
          if (item.title === '本月利润数') {
            item.number.number[0] =  data.month.profit
          }
          if (item.title === '本月订单成本') {
            item.number.number[0] =  data.month.cost
          }
          item.number = { ...item.number }
        })
      })
    },
    changeTiming() {
      setInterval(() => {
        this.getOverview()
      }, 30000)
    }
  }
}
</script>

<style lang="scss" scoped>
#center {
  display: flex;
  flex-direction: column;
  .top {
    width: 100%;
    .item {
      align-items: center;
      text-align: center;
      border-radius: 6px;
      padding-top: 8px;
      margin-top: 8px;
      width: 99%;
      height: 70px;
      .dv-dig-flop {
        align-items: center;
        text-align: center;
        width: 150px;
        height: 30px;
      }
    }
  }
  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    .item {
      border-radius: 6px;
      padding-top: 8px;
      margin-top: 8px;
      width: 32%;
      height: 70px;
      .dv-dig-flop {
        width: 150px;
        height: 30px;
      }
    }
  }
  .down {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    .item {
      border-radius: 6px;
      padding-top: 8px;
      margin-top: 8px;
      width: 24%;
      height: 70px;
      .dv-dig-flop {
        width: 150px;
        height: 30px;
      }
    }
  }
}
</style>
